package fuza.android.thetrafficsigns;

import java.util.ArrayList;
import java.util.HashMap;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ListView;

import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.app.SherlockListFragment;

import fuza.android.thetrafficsigns.help.LazyAdapter_Rambu;

public class FragmentRambu extends SherlockListFragment {

	LazyAdapter_Rambu adapter;
	Intent detail_prohibition;

	public static final String KEY_NAME_RAMBU = "title";
	public static final String KEY_GAMBAR_RAMBU = "img";

	public SherlockFragmentActivity getSherlockActivity() {
		return super.getSherlockActivity();
	}

	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onViewCreated(view, savedInstanceState);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment_rambu, container, false);

		detail_prohibition = new Intent(getActivity(),
				GridProhibitionSign.class);

		ListView ls = (ListView) view.findViewById(android.R.id.list);

		ArrayList<HashMap<String, String>> rambulist = new ArrayList<HashMap<String, String>>();

		for (int i = 0; i < 4; i++) {
			// creating new HashMap
			HashMap<String, String> map = new HashMap<String, String>();

			if (i == 0) {
				map.put(KEY_NAME_RAMBU, "Prohibition Signs");
				map.put(KEY_GAMBAR_RAMBU, "ram_larangan");

			} else if (i == 1) {
				map.put(KEY_NAME_RAMBU, "Warning Signs");
				map.put(KEY_GAMBAR_RAMBU, "ram_peringatan");
			} else if (i == 2) {
				map.put(KEY_NAME_RAMBU, "Command Signs");
				map.put(KEY_GAMBAR_RAMBU, "ram_perintah");
			} else if (i == 3) {
				map.put(KEY_NAME_RAMBU, "Guide Signs");
				map.put(KEY_GAMBAR_RAMBU, "ram_petunjuk");
			}

			rambulist.add(map);
		}

		adapter = new LazyAdapter_Rambu(getActivity(), rambulist);
		ls.setAdapter(adapter);


		  ls.setOnItemLongClickListener(new OnItemLongClickListener() {
		  
		  @Override 
		  public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
			  // TODO Auto-generated method stub
		  
		  Log.i("masuukdetailRambu", arg2+"");
		  
		  switch (arg2) {
		        case 0:
		        detail_prohibition.putExtra("jenis","prohibition");
		        startActivity(detail_prohibition);
		        break;
		  
		        case 1:
		        detail_prohibition.putExtra("jenis", "warning");
		        startActivity(detail_prohibition);
		        break;
		  
		        case 2:
		        detail_prohibition.putExtra("jenis", "command");
		        startActivity(detail_prohibition);
		        break;
		        
		        case 3:
		        detail_prohibition.putExtra("jenis", "guide");
		        startActivity(detail_prohibition);
		        break;
		        }
		  return false;
		  } });
		 
		return view;
	}
}
